﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using Kooboo.Commerce.AddIn;

namespace Kooboo.Commerce.Validators
{
    [Export(typeof(IValidator))]
    public class Regex : IValidator
    {
        public string Name
        {
            get {

                return "Regex";
            }
        }

        public bool Validate(string value, List<ValidatorParameter> args)
        {
            var pattern = args.Where(i => i.Name == "Pattern").Select(i => i.Value).FirstOrDefault();

            var regex = new System.Text.RegularExpressions.Regex(pattern);
            return regex.IsMatch(value);
        }

        public List<ValidatorParameter> GetParameters()
        {
            return new List<ValidatorParameter>()
            {
                new ValidatorParameter{ Name = "Pattern", Example = "(100)"}
            };
        }

    }
}